<template>
  <div class="order-extra-fee-bg">
    <el-card class="order-extra-fee-card">
      <div class="order-extra-fee-header">
        <el-button @click="goBack" icon="ArrowLeft">返回</el-button>
        <div class="order-extra-fee-title">添加额外费用</div>
      </div>
      <el-form :model="form" label-width="80px" class="extra-fee-form">
        <el-form-item label="费用类型">
          <el-select v-model="form.fee_type" placeholder="请选择费用类型">
            <el-option label="高速费" value="高速费" />
            <el-option label="停车费" value="停车费" />
            <el-option label="附加费" value="附加费" />
          </el-select>
        </el-form-item>
        <el-form-item label="金额">
          <el-input v-model="form.amount" type="number" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="form.description" type="textarea" rows="2" placeholder="可选，费用说明" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitExtraFee" :loading="loading">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { http } from '../utils/request'
import { ElMessage } from 'element-plus'
import { orderExtraFeeAPI } from '@/api/order'

const route = useRoute()
const router = useRouter()
const orderId = route.params.id
const form = ref({ fee_type: '', amount: '', description: '' })
const loading = ref(false)

function goBack() {
  router.go(-1)
}

async function submitExtraFee() {
  if (!form.value.fee_type || !form.value.amount) {
    ElMessage.warning('请填写完整信息')
    return
  }
  loading.value = true
  try {
    await orderExtraFeeAPI.createExtraFee({
      order: orderId,
      fee_type: form.value.fee_type,
      amount: form.value.amount,
      description: form.value.description
    })
    ElMessage.success('额外费用已添加')
    router.replace(`/order/detail/${orderId}`)
  } catch (e) {
    ElMessage.error('添加失败')
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.order-extra-fee-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, #fff 60%, #e6f7ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.order-extra-fee-card {
  width: 480px;
  border-radius: 18px;
  box-shadow: 0 4px 24px 0 rgba(34,34,34,0.08);
  padding: 32px 36px 24px 36px;
  position: relative;
}
.order-extra-fee-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
}

.order-extra-fee-title {
  font-size: 26px;
  font-weight: bold;
  color: #222;
  text-align: center;
  margin: 0 auto;
  letter-spacing: 2px;
}
.extra-fee-form {
  margin-top: 24px;
}
</style> 